package com.qianfeng.smartplatform.utils;/*
 *@Description:
 *@author:赵健
 *@Date:zjzzz 2022/9/7 16:20
 */

import java.util.Collections;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;

public class MyStringUtils {
    public static String salt = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890";


    public static String createRandomString(int lenght) {
        List<String> list = salt.chars().mapToObj(shuzi -> (char)shuzi + "").collect(Collectors.toList());
        // System.err.println(list);
        StringBuffer stringBuffer = new StringBuffer();
        //打乱集合
        Collections.shuffle(list);
        //创建一个随机的对象
        Random random = new Random();
        for (int i = 0; i < lenght; i++) {
            //随机得到一个数字
            int randomNum = random.nextInt(356554545);
            //从指定的下标获取数据
            stringBuffer.append(list.get(randomNum % list.size()));
        }
        return stringBuffer.toString();
    }
}
